<template>
  <!--充值 原路返回-->
  <uni-popup ref="refundOriginal">
    <uni-popup-dialog
        type="info"
        cancelText="取消"
        confirmText="确认退款"
        title="余额退款"
        @close="cancel"
        @confirm="submitForm"
        before-close>
      <template v-slot="content">
        <view class="tip">
          <i class="iconfont colorIcon" style="margin-right: 10rpx;font-size: 26rpx;">&#xe70f;</i> 温馨提示：仅支持退回原充值账号
        </view>
        <uni-forms
            ref="form"
            :modelValue="form"
            :rules="rules"
            :label-width="75" type="line" label-align="right"
            class="paddingAll">
          <uni-forms-item label="退款金额" name="availableBalance">
            <uni-easyinput type="text" v-model="form.availableBalance" disabled/>
          </uni-forms-item>
          <uni-forms-item name="payerName" label="退款人" v-if="form.type != 3">
            <uni-easyinput v-model="form.payerName" disabled/>
          </uni-forms-item>
          <uni-forms-item name="name" label="退款单位" v-if="staffInfo.companyId != 0 && form.type == 3">
            <uni-easyinput v-model="form.name" disabled/>
          </uni-forms-item>
          <uni-forms-item name="type" label="退款渠道">
            <uni-data-select v-model="form.channel" :localdata="dicts.ec_trading_channel" disabled/>
          </uni-forms-item>
          <uni-forms-item name="payerAccount" label="退款账号">
            <uni-easyinput v-model="form.payerAccount" disabled/>
          </uni-forms-item>
          <uni-forms-item name="city" label="开户城市" v-if="form.channel == 3">
            <uni-easyinput v-model="form.city" type="text" placeholder="请输入开户城市"/>
          </uni-forms-item>
          <uni-forms-item name="bank" label="开户支行" v-if="form.channel == 3">
            <uni-easyinput v-model="form.bank" type="text" placeholder="请输入开户支行"/>
          </uni-forms-item>
          <uni-forms-item name="payPassword" label="支付密码" required>
            <uni-easyinput v-model="form.payPassword" type="password" placeholder="请输入支付密码"/>
          </uni-forms-item>
          <uni-forms-item name="roleIds" label="服务费">
            <view style="font-size: 26rpx;color: #606266;padding-top: 15rpx;">￥0.00元</view>
            <view style="font-size: 22rpx;color: #606266;">根据不同充值渠道（微信、支付宝等）的收费标准，退款时系统可能会扣除支付机构收取的服务费，费率为0.6%。</view>
          </uni-forms-item>
        </uni-forms>
      </template>
    </uni-popup-dialog>
  </uni-popup>
</template>

<script>
import {getDictsByNameForUni} from "@/utils/dicts";
import {getBalancePay, refundPay} from "@/api/ec/person/fee/ecAccountBalancePay";

export default {
  props: {},
  data() {
    return {
      // 数据字典
      dicts: {
        ec_trading_channel: [],
      },
      // 个人信息
      staffInfo: this.$store.getters.staffInfo,
      // 服务费
      serverMoney: '￥0.00元',
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        payPassword: {rules: [{required: true, errorMessage: '请输入支付密码'}]},
      },
    };
  },
  created() {
    this.getDicts();
  },
  methods: {
    /**加载数据字典*/
    getDicts() {
      this.dicts.ec_trading_channel = getDictsByNameForUni("ec_trading_channel");
    },
    /** 打开弹出框 */
    toOpenDialog(data) {
      this.form = data;
      this.$refs.refundOriginal.open('center')
      this.getBalancePay();
    },
    /** 取消按钮 */
    cancel() {
      this.$refs.refundOriginal.close()
    },
    /** 获取充值信息 */
    getBalancePay() {
      getBalancePay(this.form.id).then(res => {
        this.form = res.data
      })
    },
    /** 确认退款,确定按钮 */
    submitForm() {
      this.$refs.form.validate().then(valid => {
        if (valid) {
          this.$modal.loading();
          refundPay(this.form).then(response => {
            uni.hideLoading()
            this.$modal.msgSuccess("退款申请成功，请等待审核！");
            this.$emit("success", "");
            setTimeout(() => {
              this.cancel()
            }, 300)
          }).catch(() => {
            uni.hideLoading()
          });
        }
      });
    },
  }
};
</script>
<style scoped lang="scss">

::v-deep .uni-popup-dialog {
  width: 90%;
}

::v-deep .uni-dialog-content {
  padding: 20rpx;
  display: block;
}

.tip {
  background: #E6F6EF;
  padding: 15rpx;
  font-size: 22rpx;
  font-weight: 400;
  color: #555b65;
  line-height: 35rpx;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: baseline;
  -ms-flex-align: baseline;
  align-items: baseline;
  margin-bottom: 25rpx;
}

.show-text {
  color: #666;
  padding: 15rpx;
  background: #F7F6F6;

  i {
    font-size: 26rpx;
    margin-right: 10rpx;
  }

  span {
    font-size: 26rpx;
  }

  p {
    font-size: 26rpx;
    text-indent: 1rem;
  }
}

</style>
